package com.cxx.purchasecharge.dal.impl;

import javax.persistence.Query;

import org.apache.commons.collections.CollectionUtils;

import com.cxx.purchasecharge.core.model.persistence.PaymentAccount;
import com.cxx.purchasecharge.dal.PaymentAccountDao;
import com.cxx.purchasecharge.dal.common.MyGenericDaoImpl;

public class PaymentAccountDaoImpl extends MyGenericDaoImpl<PaymentAccount, Long> implements PaymentAccountDao {

	public PaymentAccountDaoImpl() {
		super(PaymentAccount.class);
	}

	@Override
	public PaymentAccount findByName(String name) {
		String sql = "select c from PaymentAccount c where c.name=?1";
		Query query = getEntityManager ().createQuery (sql, PaymentAccount.class);
		query.setParameter (1, name);
		return CollectionUtils.isNotEmpty (query.getResultList ()) ? (PaymentAccount)query.getResultList ().get (0) : null;
	}

	@Override
	public PaymentAccount findByNumber(String number) {
		String sql = "select c from PaymentAccount c where c.number=?1";
		Query query = getEntityManager ().createQuery (sql, PaymentAccount.class);
        query.setParameter (1, number);
        return CollectionUtils.isNotEmpty (query.getResultList ()) ? (PaymentAccount)query.getResultList ().get (0) : null;
	}

}
